/*
    加工处理最终回复用户消息的模板
 */
module.exports= options =>{
    let replyMessage=
        `<xml>
            <ToUserName><![CDATA[${options.toUserName}]]></ToUserName>
            <FromUserName><![CDATA[${options.fromUserName}]]></FromUserName>
            <CreateTime>${Date.now()}</CreateTime>
            <MsgType><![CDATA[${options.msgType}]]></MsgType>`;
    /*
    mediaId  是上传素材  先把素材 上传到微信服务器，微信服务器会给你一个 素材id
     */
    if(options.msgType=='text'){
        replyMessage+=`<Content><![CDATA[${options.content}]]></Content>`
    }else if(options.msgType=='image'){
        replyMessage+=`<Image><MediaId><![CDATA[${options.mediaId}]]></MediaId></Image>`
    }else if(options.msgType=='voice'){
        replyMessage+=`<Voice><MediaId><![CDATA[${options.mediaId}]]></MediaId></Voice>`
    }else if(options.msgType=='video'){
        replyMessage+=`<Video>
                            <MediaId><![CDATA[${options.mediaId}]]></MediaId>
                            <Title><![CDATA[${options.title}]]></Title>
                            <Description><![CDATA[${options.description}]]></Description>
                        </Video>`
    }else if(options.msgType=='music'){
        replyMessage+=`<Music>
                            <Title><![CDATA[${options.title}]]></Title>
                            <Description><![CDATA[${options.description}]]></Description>
                            <MusicUrl><![CDATA[${options.musicUrl}]]></MusicUrl>
                            <HQMusicUrl><![CDATA[${options.hqMusicUrl}]]></HQMusicUrl>
                            <ThumbMediaId><![CDATA[${options.mediaId}]]></ThumbMediaId>
                        </Music>`
    }else if(options.msgType=='news'){
        //这里 最麻烦 ，因为中间  item  是循环创建的，
        replyMessage+=`<ArticleCount>${options.content.length}</ArticleCount>
            <Articles>`;
            // 便利数据
            options.content.forEach(item =>{
                replyMessage+=`<item>
                        <Title><![CDATA[${item.title}]]></Title>
                        <Description><![CDATA[${item.description}]]></Description>
                        <PicUrl><![CDATA[${item.picUrl}]]></PicUrl>
                        <Url><![CDATA[${item.url}]]></Url>
                    </item>`
            })
        replyMessage+=`</Articles>`
    }

    replyMessage+=`</xml>`;
    // console.log(replyMessage)
    //最终回复给用户的xml数据
    return replyMessage;
}